Repository navigation
Support zero theta in dcsbm() and directed_dcsbm() - #70
Draft
alexpghayes wants to merge 1 commit into
Draft
alexpghayes wants to merge 1 commit into
alexpghayes wants to merge 1 commit into
Conversation
With sort_nodes = TRUE, nodes were sorted by sorting the rows of the membership matrix, which sends all-zero rows (theta = 0) to the bottom, while z had been sorted separately and theta was read back from X@x in block order. So zero theta misaligned z, X and theta. The validators said theta must be "strictly positive" but only rejected negatives. Allow theta = 0 (isolated nodes): sort within blocks by permuting z and theta together with order(z, -theta), then build X from them. For positive theta this gives exactly the same models as before. Blocks whose theta are all zero stay zero under force_identifiability instead of becoming NaN. Validator messages and docs now say non-negative. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 18, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
With
sort_nodes = TRUE,sort_by_all_columns()sent the all-zero rows ofXto the bottom, butzhad been sorted separately, andtheta <- X@xassumed block order. The co-factor branch ofdirected_dcsbm()had the same pattern. The validators said theta must be "strictly positive" but only rejected negatives.Fix
As decided by the maintainer, zero theta is supported and gives isolated nodes:
dcsbm()and the co-factor branch ofdirected_dcsbm()now sort within blocks by permutingzandthetatogether withorder(z, -theta), and then buildX(andY) from them, like the shared-blocks branch.l1_normalize_within()leaves a block whose theta are all zero at zero instead ofNaN, soforce_identifiability = TRUEworks too.dcsbm,directed_dcsbm,mmsbm) now say "must be non-negative", and thethetadocs fordcsbm(),directed_dcsbm()andchung_lu()say zero theta gives a node with no edges.Tests
New
tests/testthat/test-zero-theta.R: after construction, each row ofXhas its weight in the column of its blockz,rowSums(X) == theta, sorted models are sorted by block and then by decreasing theta, and zero-theta nodes get no sampled edges. This is checked fordcsbm()(k = 1, 2) anddirected_dcsbm()(co-factor and shared blocks), with every combination ofsort_nodesandforce_identifiability. Fails onmain(20 failures), passes here. Full suite passes. Docs regenerated with roxygen2 7.3.2.Related bug, in a stacked PR
While fixing this I found that sorted models don't pair
theta[i]with nodei's own block.zis sorted first andthetais then laid on in input order, so block 1 always gets the firstblock_sizes[1]elements oftheta:Unsorted models assign theta to blocks at random, so the two settings give different models whenever
thetaisn't exchangeable. Fixing that changes seeded output and the pinned reference values intest-directed-sbms.R, so it is a separate PR stacked on this one, for you to take or leave.NEWS
Left out to avoid conflicting with #59. Suggested bullet under Bug fixes:
🤖 Generated with Claude Code